﻿#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    init();

    resourceInit();


}

Widget::~Widget()
{
    view->deleteLater();
}

void Widget::init()
{
    view = new QWebEngineView(this);
    view->setContextMenuPolicy(Qt::NoContextMenu); //禁止鼠标右键
    view->load(QUrl("https://mpkf.weixin.qq.com/"));
    view->page()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
    view->show();
}

void Widget::resourceInit()
{
    this->setWindowTitle(QString(tr("windowstitle")));
    QIcon icon(":/icon/windowtitleicon.png");
    this->setWindowIcon(icon);
    QDesktopWidget *desktopWidget = QApplication::desktop();
    QRect deskRect = desktopWidget->availableGeometry();
    //QRect screenRect = desktopWidget->screenGeometry();
    this->setMinimumSize(deskRect.width() / 1.5, deskRect.height() / 1.3);
    //this->setFixedSize(deskRect.width() / 1.5, deskRect.height() / 1.5);
}

void Widget::resizeEvent(QResizeEvent*)
{
    view->resize(this->size());
}

void Widget::closeEvent(QCloseEvent *event)
{
    QMessageBox::StandardButton button;
    button = QMessageBox::question(this, QString(tr("quittitle")), QString(tr("quitcontent?")), QMessageBox::Yes | QMessageBox::No);
    if(button == QMessageBox::No)
    {
        event->ignore();
    }
    else if(button == QMessageBox::Yes)
    {
        event->accept();
    }
}

void Widget::keyPressEvent(QKeyEvent *event)
{
    switch (event->key()) {
//    case Qt::Key_Escape:
//        this->showMinimized();
//        break;
    case Qt::Key_F5:
        view->reload();
        break;
    default:
        break;
    }
}


//int Widget::ChMessageOkOrCancel(QString title, QString info)
//{
//    QMessageBox msg;
//    msg.setWindowTitle(title);
//    msg.setText(info);
//    msg.setStyleSheet("color:rgb(220, 0, 0);font: 12pt");
//    msg.setIcon(QMessageBox::Information);
//    msg.addButton(tr("msgyes"),QMessageBox::YesRole);
//    msg.addButton(tr("msgno"),QMessageBox::NoRole);
//    return msg.exec();
//}
